﻿using System;

namespace Mbl.ParameterizedTest.FluentCollectionBuilding.Expectors.GeneralExpectations
{
    public class TypeExpectation<TOut> : IExpectation<TOut>        
    {
        private readonly Type _expectedType;

        public TypeExpectation(Type expectedType)
        {
            _expectedType = expectedType;
        }

        public AssertionResult HoldsFor(Func<TOut> actual)
        {
            var actualType = actual().GetType();
            if (actualType != _expectedType)
            {
                return AssertionResult.Error(
                    $"Expected an object of type <{_expectedType.Name}>, but got a <{actualType.Name}>.");
            }

            return AssertionResult.Success;
        }        
    }
}
